const { ccclass, property } = cc._decorator;
declare let eManager,dbh,DBManager,i18n,JsonHttp;
import BaseView from "../../component/BaseView";
import MeiTong from "../MeiTong";
import YanYing from "../YanYing";
import YanXian from "../YanXian";
import JieMao from "../JieMao";
import MeiMao from "../MeiMao";
import UIHelper = require("../../component/UIHelper");

@ccclass
export default class HuaZhuangOneView extends BaseView {
    //触摸区域
    @property(cc.Node)
    bg: cc.Node = null;
    //美瞳
    @property(MeiTong)
    MeiTong: MeiTong = null;
    //眼影
    @property(YanYing)
    YanYing: YanYing = null;
    //眼线
    @property(YanXian)
    YanXian: YanXian = null;
    //睫毛
    @property(JieMao)
    JieMao: JieMao = null;
    //眉毛
    @property(MeiMao)
    MeiMao: MeiMao = null;


    //下一步
    @property(cc.Node)
    nodeNextPoint: cc.Node = null;
    //完成
    @property(cc.Node)
    nodeDone: cc.Node = null;

    @property(cc.Node)
    showNode: cc.Node[] = [];

    @property(cc.Node)
    hideNode: cc.Node[] = [];

    @property(cc.Node)
    btnClose: cc.Node = null;

    _point = 1;
    _isPlay = false;
    _isStart = false;//是否是剧情前触发
    onLoad() {
        super.onLoad();
        this.bg.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this);
        this.bg.on(cc.Node.EventType.TOUCH_MOVE, this.onTouchMove, this);
        this.bg.on(cc.Node.EventType.TOUCH_END, this.onTouchEnd, this);
        eManager.on("HZ_REFRESH_ICON_TIPS", this.showIconTips, this)
        eManager.on("MINI_DONE_POINT", this.donePoint, this)
        eManager.on("MINI_DONE_STEP", this.doneStep, this)
        //@ts-ignore
        this._isStart = this.node.openParam;
    };

    onClose(){
    };

    start() {
        super.start();
        this.btnClose.active = !this._isStart;
        this.updatePointShow();
    };

    donePoint(point:number){
        this.nodeNextPoint.active = true;
    };
    doneStep(){
        this.nodeDone.active = true;
        for (let index = 0; index < this.showNode.length; index++) {
            const show = this.showNode[index];
            show.active = true;
        }
        for (let index = 0; index < this.hideNode.length; index++) {
            const hide = this.hideNode[index];
            hide.active = false;
        }
    };

    updatePointShow(){
        this.MeiTong.node.active = this._point == 1;
        this.YanYing.node.active = this._point == 2;
        this.YanXian.node.active = this._point == 3;
        this.JieMao.node.active = this._point == 4;
        this.MeiMao.node.active = this._point == 5;
        switch (this._point) {
            case 1:
                this.MeiTong.initData();
                break;
            case 2:
                this.YanYing.initData();
                break;
            case 3:
                this.YanXian.initData();
                break;
            case 4:
                this.JieMao.initData();
                break;
            case 5:
                this.MeiMao.initData();
                break;
        }
        // Initializer.huaZhuangProxy.sendMakeDot(6,this._point,1);
    };

    //展示提示图片
    showIconTips(name){

    };

    //下一小阶段
    onClickNextPoint() {
        this.nodeNextPoint.active = false;
        this._point++;
        this.updatePointShow();
    };

    onTouchStart(event) {
        switch (this._point) {
            case 1:
                this.MeiTong._touchStart(event);
                break;
            case 2:
                this.YanYing._touchStart(event);
                break;
            case 3:
                this.YanXian._touchStart(event);
                break;
            case 4:
                this.JieMao._touchStart(event);
                break;
            case 5:
                this.MeiMao._touchStart(event);
                break;
        }
    };

    onTouchMove(event) {
        switch (this._point) {
            case 1:
                this.MeiTong._touchMove(event);
                break;
            case 2:
                this.YanYing._touchMove(event);
                break;
            case 3:
                this.YanXian._touchMove(event);
                break;
            case 4:
                this.JieMao._touchMove(event);
                break;
            case 5:
                this.MeiMao._touchMove(event);
                break;
        }
    };

    onTouchEnd(event) {
        switch (this._point) {
            case 2:
                this.YanYing._touchEnd(event);
                break;
            case 3:
                this.YanXian._touchEnd(event);
                break;
            case 5:
                this.MeiMao._touchEnd(event);
                break;
        }
    };

    onClickEnd(isSkip){
        let next = this.params.next && this.params.next.shift();
        if (next) {
            UIHelper.openUI(next, {
                next: this.params.next
            })
            this.node.destroy();
        }
    };

    onClickSkip(){
        this.onClickEnd(true);
    };

}
